package com.iwith.dongmoon.util;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;

public class ThreadTask extends AsyncTask<Void, Void, Void> {
	ThreadInterface threadInterface = null;
	Activity mActivity = null;
	ProgressDialog progressDialog = null;

	private static List<ProgressDialog> progressList = null;
	
	public ThreadTask(Activity _activity, ThreadInterface threadInterface) {
		this.threadInterface = threadInterface;
		this.mActivity = _activity;
		
		if(progressList==null){
			progressList=new ArrayList<ProgressDialog>();
		}		
	}

	@Override
	protected void onPreExecute() {
		progressDialog = ProgressDialog.show(mActivity, "",	"로딩 중입니다. 잠시만 기다려 주세요.", true);
		progressList.add(progressDialog);
	}

	@Override
	public void onPostExecute(Void result) {
		progressDialog.dismiss();
		threadInterface.onThreadEnd();
	}

	@Override
	protected Void doInBackground(Void... params) {
		threadInterface.onThread();
		return null;
	}

	public static void onFinishAll() {
		if(progressList!=null){
			for (int i = 0; i < progressList.size(); i++) {
				if (progressList.get(i).isShowing() == true) {
					progressList.get(i).dismiss();
				}
			}

			progressList.clear();
		}
	}
}
